import {
  createRouter,
  createWebHistory
} from 'vue-router'
import HomeView from '../views/HomeView.vue'

let beforeEnter = (to,from,next)=>{
  let token = window.localStorage.getItem("token");
  // 判断是否登录
  if(!token){
    next("/login");
    return;
  }else{
    next();
  }
}

const routes = [{
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView
  },
  {
    path: '/videos',
    name: 'videos',
    component: () => import('../views/VideoView.vue')
  },
  {
    path: '/shortvideo',
    name: 'shortvideo',
    component: () => import('../views/SmallVideoView.vue')
  },
  {
    path: '/my',
    name: 'my',
    component: () => import('../views/MyView.vue'),
    beforeEnter:beforeEnter,
  },
  {
    path: '/videodetail',
    name: 'videodetail',
    component: () => import('../views/VideoPlayDetail.vue')
  },
  {
    path: '/moviedetail',
    name: 'moviedetail',
    component: () => import('../views/MovieDetail.vue')
  },
  {
    path: '/cinemadetail',
    name: 'cinemadetail',
    component: () => import('../views/CinemaDetail.vue')
  },
  {
    path: '/citylist',
    name: 'citylist',
    component: () => import('../views/CitysList.vue')
  },
  {
    path: '/ticketpurchase',
    name: 'ticketpurchase',
    component: () => import('../views/TicketPurchase.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/seatselection',
    name: 'seatselection',
    component: () => import('../views/SeatSelection.vue')
  },
  {
    path: '/orderlist',
    name: 'orderlist',
    component: () => import('../views/OrderList.vue')
  },
  {
    path: '/videoplay',
    name: 'videoplay',
    component: () => import('../views/VideoPlay.vue')
  },
  {
    path: '/wishview',
    name: 'wishview',
    component: () => import('../views/WishView.vue')
  },

  {
    path: '/live',
    name: 'live',
    component: () => import('../views/VideoLivePlay.vue')
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('../views/SearchView.vue')
  },
  {
    path: '/activity',
    name: 'activity',
    component: () => import('../views/ActivityView.vue')
  },
  {
    path: '/turntable',
    name: 'turntable',
    component: () => import('../views/TurntableView.vue')
  },
  {
    path: '/activitylist',
    name: 'activitylisy',
    component: () => import('../views/ActivitulistsView.vue'),
    beforeEnter:beforeEnter,
  }
]

const router = createRouter({
  // createWeb History 历史模式
  // createWeb Hash History hash模式
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router